package org.csu.mypetstore.persistence;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.csu.mypetstore.domain.LineItem;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LineItemMapper {
    @Select("        SELECT\n" +
            "            ORDERID,\n" +
            "            LINENUM AS lineNumber,\n" +
            "            ITEMID,\n" +
            "            QUANTITY,\n" +
            "            UNITPRICE\n" +
            "        FROM LINEITEM\n" +
            "        WHERE ORDERID = #{orderId}")
    List<LineItem> getLineItemsByOrderId(int orderId);

    @Insert("        INSERT INTO LINEITEM (ORDERID, LINENUM, ITEMID, QUANTITY, UNITPRICE)\n" +
            "        VALUES (#{orderId}, #{lineNumber}, #{itemId}, #{quantity}, #{unitPrice})")
    boolean insertLineItem(LineItem lineItem);
}
